using System;
using System.Collections.Generic;
using PluginFrame;

namespace PcrDataStructure
{
	[Serializable]
	public class PcrStandardCurve : IPcrStandardCurve
	{
		protected IAnalysisResult[,] mStandardCurveData;

		protected List<IPcrCell>[,] mStandardPcrCells;

		protected List<double>[,] mCellConcentrations;

		protected List<double>[,] mCellCycles;

		protected List<int>[,] mCellIDs;

		protected string mFileName;

		public string FileName
		{
			get
			{
				return mFileName;
			}
			set
			{
				mFileName = value;
			}
		}

		public List<double>[,] CellConcentrations
		{
			get
			{
				return mCellConcentrations;
			}
		}

		public List<double>[,] CellCycles
		{
			get
			{
				return mCellCycles;
			}
		}

		public List<int>[,] CellIDs
		{
			get
			{
				return mCellIDs;
			}
		}

		public IAnalysisResult[,] GetStandardCurveData
		{
			get
			{
				return mStandardCurveData;
			}
		}

		public List<double> GetChannelCellConcentrations(int channel, int targetIndex)
		{
			if (mCellConcentrations == null)
			{
				return null;
			}
			if (channel >= 0 && channel < mCellConcentrations.GetLength(0) && targetIndex >= 0 && targetIndex < mCellConcentrations.GetLength(1))
			{
				return mCellConcentrations[channel, targetIndex];
			}
			return null;
		}

		public List<double> GetChannelCellCycles(int channel, int targetIndex)
		{
			if (mCellCycles == null)
			{
				return null;
			}
			if (channel >= 0 && channel < mCellCycles.GetLength(0) && targetIndex >= 0 && targetIndex < mCellCycles.GetLength(1))
			{
				return mCellCycles[channel, targetIndex];
			}
			return null;
		}

		public List<int> GetChannelCellIDs(int channel, int targetIndex)
		{
			if (mCellIDs == null)
			{
				return null;
			}
			if (channel >= 0 && channel < mCellIDs.GetLength(0) && targetIndex >= 0 && targetIndex < mCellIDs.GetLength(1))
			{
				return mCellIDs[channel, targetIndex];
			}
			return null;
		}

		public List<IPcrCell> GetStandardPcrCells(int channel, int targetIndex)
		{
			if (mStandardCurveData == null)
			{
				return null;
			}
			if (channel >= 0 && channel < mStandardPcrCells.GetLength(0) && targetIndex >= 0 && targetIndex < mStandardPcrCells.GetLength(1))
			{
				return mStandardPcrCells[channel, targetIndex];
			}
			return null;
		}

		public IAnalysisResult GetChannelStandardCurveData(int channel, int targetIndex)
		{
			if (mStandardCurveData == null)
			{
				return null;
			}
			if (channel >= 0 && channel < mStandardCurveData.GetLength(0) && targetIndex >= 0 && targetIndex < mStandardCurveData.GetLength(1))
			{
				return mStandardCurveData[channel, targetIndex];
			}
			return null;
		}

		public PcrStandardCurve(IAnalysisResult[,] analysisResults, IPcrExperiment rawPcrExperiment, IPcrExperimentProject rawProject)
		{
			mStandardCurveData = analysisResults;
			int length = mStandardCurveData.GetLength(0);
			int length2 = mStandardCurveData.GetLength(1);
			mCellConcentrations = new List<double>[length, length2];
			mCellCycles = new List<double>[length, length2];
			mCellIDs = new List<int>[length, length2];
			mStandardPcrCells = new List<IPcrCell>[length, length2];
			IAnalysisResult[,] analysisResults2 = rawPcrExperiment.GetAnalysisResults(rawProject);
			IPcrExperiment pcrExperiment = null;
			for (int i = 0; i < length; i++)
			{
				for (int j = 0; j < length2; j++)
				{
					IQuantitativeAnalysisResult quantitativeAnalysisResult = mStandardCurveData[i, j] as IQuantitativeAnalysisResult;
					IQuantitativeAnalysisResult quantitativeAnalysisResult2 = analysisResults2[i, j] as IQuantitativeAnalysisResult;
					if (quantitativeAnalysisResult2 == null || quantitativeAnalysisResult == null || quantitativeAnalysisResult2.StandardPointSeries == null)
					{
						continue;
					}
					mCellConcentrations[i, j] = new List<double>();
					mCellCycles[i, j] = new List<double>();
					mCellIDs[i, j] = new List<int>();
					mStandardPcrCells[i, j] = new List<IPcrCell>();
					for (int k = 0; k < quantitativeAnalysisResult2.StandardPointSeries.Points.Count; k++)
					{
						mCellConcentrations[i, j].Add(quantitativeAnalysisResult2.StandardPointSeries.Points[k].ValueX);
						mCellCycles[i, j].Add(quantitativeAnalysisResult2.StandardPointSeries.Points[k].ValueY);
						int num = Convert.ToInt32(quantitativeAnalysisResult2.StandardPointSeries.Points[k].Label);
						mCellIDs[i, j].Add(num);
						foreach (IPcrCell cell in quantitativeAnalysisResult.Project.Cells)
						{
							if (cell.CellID == num)
							{
								mStandardPcrCells[i, j].Add(cell);
								pcrExperiment = cell.SubModule.PcrExperiment;
							}
						}
					}
				}
			}
			if (pcrExperiment == null)
			{
				return;
			}
			foreach (IPcrExperimentProject project in pcrExperiment.Projects)
			{
				if (!project.Name.Equals(rawProject.Name) && pcrExperiment.CurrentImportStandardCurve != null && pcrExperiment.CurrentImportStandardCurve.ContainsKey(project.Name))
				{
					pcrExperiment.CurrentImportStandardCurve.Remove(project.Name);
				}
			}
		}
	}
}
